home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 4 / Example 4.11 / Debug / Shaders / terrain.ps
Encoding:
Text File  |  2006-06-22  |  1.1 KB  |  32 lines

  1. //////////////////////////////////////////////////////////////////////////
  2. //                                                                      //
  3. //               Terrain Texture Splatting Pixelshader                  //
  4. //                                                                      //
  5. //                   Written by C. Granberg, 2006                       //
  6. //                                                                      //
  7. //////////////////////////////////////////////////////////////////////////
  8.  
  9. sampler alpha;
  10. sampler texture1;
  11. sampler texture2;
  12. sampler texture3;
  13.  
  14. float4 Main(float2 alphaUV : TEXCOORD0, float2 colorUV : TEXCOORD1) : COLOR
  15. {
  16.     //Sample the textures
  17.     float4 a  = tex2D(alpha, alphaUV);
  18.     float4 c1 = tex2D(texture1, colorUV);
  19.     float4 c2 = tex2D(texture2, colorUV);
  20.     float4 c3 = tex2D(texture3, colorUV);
  21.  
  22.     //Calculate the inverse
  23.     float inverse = 1.0f / (a.r + a.g + a.b);
  24.     
  25.     //Multiply with alpha texture
  26.     c1 *= a.b * inverse;
  27.     c2 *= a.g * inverse;
  28.     c3 *= a.r * inverse;
  29.  
  30.     //Return result
  31.     return c1 + c2 + c3;
  32. }